package com.chisheng.caa.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.chisheng.caa.mapper.MajorMapper;
import com.chisheng.caa.pojo.dto.MajorDTO;
import com.chisheng.caa.pojo.entity.Major;
import com.chisheng.caa.service.MajorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Chisheng Chen
 */
@Service
public class MajorServiceImpl implements MajorService {

    @Resource
    private MajorMapper majorMapper;

    @Override
    public List<MajorDTO> getMajorList() {
        return majorMapper.selectList(null).stream().map(major -> {
            MajorDTO dest = new MajorDTO();
            BeanUtil.copyProperties(major, dest);
            return dest;
        }).collect(Collectors.toList());
    }

    @Override
    public List<String> getMajorNameList() {
        return majorMapper.selectList(null).stream().map(Major::getMajorName)
                .collect(Collectors.toList());
    }

}
